/*   1:    */ package com.atomikos.swing;
/*   2:    */ 
/*   3:    */ import javax.swing.SwingUtilities;
/*   4:    */ 
/*   5:    */ public abstract class SwingWorker
/*   6:    */ {
/*   7:    */   private Object value;
/*   8:    */   private Thread thread;
/*   9:    */   private ThreadVar threadVar;
/*  10:    */   
/*  11:    */   private static class ThreadVar
/*  12:    */   {
/*  13:    */     private Thread thread;
/*  14:    */     
/*  15:    */     ThreadVar(Thread t)
/*  16:    */     {
/*  17: 52 */       this.thread = t;
/*  18:    */     }
/*  19:    */     
/*  20:    */     synchronized Thread get()
/*  21:    */     {
/*  22: 53 */       return this.thread;
/*  23:    */     }
/*  24:    */     
/*  25:    */     synchronized void clear()
/*  26:    */     {
/*  27: 54 */       this.thread = null;
/*  28:    */     }
/*  29:    */   }
/*  30:    */   
/*  31:    */   protected synchronized Object getValue()
/*  32:    */   {
/*  33: 64 */     return this.value;
/*  34:    */   }
/*  35:    */   
/*  36:    */   private synchronized void setValue(Object x)
/*  37:    */   {
/*  38: 71 */     this.value = x;
/*  39:    */   }
/*  40:    */   
/*  41:    */   public abstract Object construct();
/*  42:    */   
/*  43:    */   public void finished() {}
/*  44:    */   
/*  45:    */   public void interrupt()
/*  46:    */   {
/*  47: 91 */     Thread t = this.threadVar.get();
/*  48: 92 */     if (t != null) {
/*  49: 93 */       t.interrupt();
/*  50:    */     }
/*  51: 95 */     this.threadVar.clear();
/*  52:    */   }
/*  53:    */   
/*  54:    */   public Object get()
/*  55:    */   {
/*  56:    */     for (;;)
/*  57:    */     {
/*  58:107 */       Thread t = this.threadVar.get();
/*  59:108 */       if (t == null) {
/*  60:109 */         return getValue();
/*  61:    */       }
/*  62:    */       try
/*  63:    */       {
/*  64:112 */         t.join();
/*  65:    */       }
/*  66:    */       catch (InterruptedException e)
/*  67:    */       {
/*  68:115 */         Thread.currentThread().interrupt();
/*  69:116 */         return null;
/*  70:    */       }
/*  71:    */     }
/*  72:    */   }
/*  73:    */   
/*  74:    */   public SwingWorker()
/*  75:    */   {
/*  76:127 */     final Runnable doFinished = new Runnable()
/*  77:    */     {
/*  78:    */       public void run()
/*  79:    */       {
/*  80:128 */         SwingWorker.this.finished();
/*  81:    */       }
/*  82:130 */     };
/*  83:131 */     Runnable doConstruct = new Runnable()
/*  84:    */     {
/*  85:    */       public void run()
/*  86:    */       {
/*  87:    */         try
/*  88:    */         {
/*  89:134 */           SwingWorker.this.setValue(SwingWorker.this.construct());
/*  90:    */         }
/*  91:    */         finally
/*  92:    */         {
/*  93:137 */           SwingWorker.this.threadVar.clear();
/*  94:    */         }
/*  95:140 */         SwingUtilities.invokeLater(doFinished);
/*  96:    */       }
/*  97:143 */     };
/*  98:144 */     Thread t = new Thread(doConstruct);
/*  99:145 */     this.threadVar = new ThreadVar(t);
/* 100:    */   }
/* 101:    */   
/* 102:    */   public void start()
/* 103:    */   {
/* 104:152 */     Thread t = this.threadVar.get();
/* 105:153 */     if (t != null) {
/* 106:154 */       t.start();
/* 107:    */     }
/* 108:    */   }
/* 109:    */ }


/* Location:           C:\myfile\mysoft\apache-maven-3.5.0-bin\apache-maven-3.5.0\myrep\com\atomikos\atomikos-util\3.7.0\atomikos-util-3.7.0.jar
 * Qualified Name:     com.atomikos.swing.SwingWorker
 * JD-Core Version:    0.7.0.1
 */